
import request from "../utils/request";

export default {
    getCollectionList(pageNum, pageSize) {
        let params = {
            pageNum: pageNum,
            pageSize: pageSize
        }
        return request.get("/collection", { params }, {
            method: "get",
        })
    },
    getCollection() {
        return request.get("/collection/getListNumber", {
            method: "get",
        })
    },
    getCollectionEditCollectionById(id) {
        const params = {
            id
        }
        return request.get("/collection/getEditCollection", { params }, {
            method: "get",
        })
    },
    getTeDingCollection(pageNum, pageSize, name, classification, valueSelectProtect, valueSelectState) {
        // 扁平化所有参数
        const params = {
            pageNum,
            pageSize,
            name,          // 直接平铺参数
            classification,
            valueSelectProtect,
            valueSelectState
        };
        console.log(params);
        return request.get("/collection/getSpecificCollection", { params }, {
            method: "get",
        })
    },
    getCollectionDetail(id) {
        const params = {
            id
        };
        return request.get("/collection/getOneCollection", { params },
            {
                method: "get",
            })
    },
    updateCollection(collection) {
        return request.put("/collection", collection, {
            headers: {
                "Content-Type": "application/json", // 明确指定请求头
            },
            method: "put",
        })
    },
    addCollection(listTableCollectionAddDetail, provenanceSource) {
        return request.post("/collection", {
            listTableCollectionAddDetail: listTableCollectionAddDetail,
            provenanceSource: provenanceSource
        }, {
            headers: {
                "Content-Type": "application/json", // 明确指定请求头
            },
            method: "post",
        })
    },
    getColllectionReviewStats() {
        return request.get("/collection/getReviewCollection", {
            method: "get",
        })
    },
    getCollectionReviewListtable(pageNum, pageSize) {
        const params = {
            pageNum,
            pageSize
        }
        return request.get("/collection/getReviewCollectionDetail", { params }, {
            method: "get",
        })
    },
    updateCollectionReview(id) {
        let params;
        if (typeof id === "number") {
            params = {
                id: [id]
            };
        } else {
            params = {
                id: id
            };
        }
        return request.patch("/collection", params, {
            headers: {
                'Content-Type': 'application/json'
            },
            method: "patch",
        });
    },
    getCollectionReviewSpecie(pageNum, pageSize, name, subcategory, time) {
        // 假设你的时间参数是一个数组
        const params = {
            pageNum,
            pageSize,
            name,
            subcategory,
            // 安全访问 time 数组，未选择时间时自动过滤字段
            ...(time?.[0] && { startTime: time[0] }),  // 仅当 time[0] 存在时添加 startTime
            ...(time?.[1] && { endTime: time[1] })     // 仅当 time[1] 存在时添加 endTime
        }
        console.log(params);
        return request.get("/collection/getSpecieReviewCollection", { params }, {
            method: "get",
        })
    },
    loadingExcelCollection(){
        return request.get("/museum/collection", {
            method: "get",
            responseType: 'blob' // 必须声明响应类型为二进制大对象
        })
    }

}